package com.yangyang.jikehw.mr;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, Text, FlowBean> {

    /**
     * 聚合
     *
     * @param key     偏移量
     * @param value   行
     * @param context
     * @throws IOException
     * @throws InterruptedException 作业要求输出：手机号码（0）上行流量（-3） 下行流量（-2）总流量
     */
    @Override
    protected void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {

        String[] fields = value.toString().split("\t");
        context.write(new Text(fields[1]),
                new FlowBean(Long.parseLong(fields[fields.length-3]),
                        Long.parseLong(fields[fields.length-2]))
        );
    }
}
